#include <iostream>
#include <list>
#include <string>
#include <sstream>
using namespace std;

class Graph
{
		
public:		
	int numNodes;
	int count;
	list<int> *adj;	

	Graph(int nodes)
	{
		this->numNodes = nodes;
		adj = new list<int>[numNodes];
		count = 0;
	}

	void addEdge(int nodeOne, int nodeTwo)
	{
		adj[nodeOne].push_back(nodeTwo);
	}

	string BFS(int s)
	{
		stringstream  result;
		result << "[";

		// Mark all the vertices as not visited
		bool *visited = new bool[numNodes];
		for(int i = 0; i < numNodes; i++)
		visited[i] = false;

		// Create a queue for BFS
		list<int> queue;

		// Mark the current node as visited and enqueue it
		visited[s] = true;
		queue.push_back(s);

		// 'i' will be used to get all adjacent vertices of a vertex
		list<int>::iterator i;

		while(!queue.empty())
		{
			// Dequeue a vertex from queue and print it
			s = queue.front();
			result << s <<  ",";
			count++;
			queue.pop_front();

			// Get all adjacent vertices of the dequeued vertex s
			// If a adjacent has not been visited, then mark it visited
			// and enqueue it
			for(i = adj[s].begin(); i != adj[s].end(); ++i)
			{
				if(!visited[*i])
				{
					visited[*i] = true;
					queue.push_back(*i);
				}
			}
		}
		result << "]" << endl;
		return result.str();
	}
};